package com.crm.dao;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.crm.entity.Variables;
import com.crm.util.ApplicationContext;

public class VariablesDAO {
	protected final Log logger = LogFactory.getLog(getClass());

	
	public  int insert(Variables v) throws Exception{
		Session session =  ApplicationContext.getHiberSession().openSession();
		Transaction tx=null;
		try {
		     tx = session.beginTransaction();
		     session.saveOrUpdate(v);
			tx.commit();
			return 0;
		}
		catch (Exception e) {
			if (tx!=null) tx.rollback();
			throw e;
		}
		finally {
			session.close();
		}
	}
	public  Variables getVariables(int busid) throws Exception{
		Session session =  ApplicationContext.getHiberSession().openSession();
		try {
		     Query query=session.createQuery("from Variables where business_id=:busid");
		     query.setInteger("busid", busid);
		     Variables v=(Variables)query.uniqueResult();
		     return v;
		}
		catch (Exception e) {
			throw e;
		}
		finally {
			session.close();
		}	
	}
	
}
